package com.company.test.classload;

import sun.misc.Launcher;
import sun.misc.URLClassPath;

import java.net.URL;
import java.net.URLClassLoader;

/**
 * @author zhangyan
 * @version $ Id: MyClassLoader.java, v 0.1 2021/2/19 15:49 zhangyan Exp $
 */
public class MyClassLoader extends ClassLoader {

    public static void main(String[] args) {
        URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
        for (URL urL : urLs) {
            System.out.println(urL);
        }

        ClassLoader classLoader = ClassLoader.getSystemClassLoader().getParent();

        System.out.println("------------------------");
        URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
        URL[] urls = urlClassLoader.getURLs();
        for (URL url : urls) {
            System.out.println(url);
        }
        System.out.println("********************************");
        String[] url1 = System.getProperty("java.class.path").split(":");

        for (String url : url1) {
            System.out.println(url);
        }

        System.out.println("================================");

        URLClassLoader classLoader1 = (URLClassLoader) ClassLoader.getSystemClassLoader();
        URL[] urls2 = classLoader1.getURLs();
        for (URL url : urls2) {
            System.out.println(url);
        }
    }

    @Override
    public Class<?> loadClass(String name) throws ClassNotFoundException {
        return super.loadClass(name);
    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        return super.findClass(name);
    }
}
